package Servlet;

import org.junit.Test;

import java.sql.*;
import JDBC.JDBC ;

/**
 * <p>Title: test</p>
 * <p>author 12427</p>
 *
 * @version ver1.0
 * @date 2021/12/20 22:28
 */
public class test {
        @Test
        public void test() throws SQLException {
            Connection connection = null ;
            try {
                 connection = JDBC.getConnection();
            Statement statement = connection.createStatement();//获取操作数据库的对象
            String sql="select * from user";
            ResultSet resultSet = statement.executeQuery(sql);//执行sql，获取结果集
            while(resultSet.next()){ //遍历结果集，取出数据
                // 得到ID、sex
                String name = resultSet.getString("user_name");

                //输出数据
                System.out.println("user："+ name);

            }
            } catch (Exception e) {
                e.printStackTrace();
            }
            finally {
                connection.close();
            }
        }
}
